package skeleton

import (
	"gitee.com/zjlsliupei/ghelp"
	"gitee.com/zjlsliupei/gweb-cli/utils"
	"github.com/beego/beego/v2/core/logs"
	"os"
	"path/filepath"
)

var (
	skeletonGitUrl string = "git@gitee.com:zjlsliupei/gweb-skeleton.git"
)

func Init(out string) {
	// 下载骨架代码
	ghelp.IsDir(out)
	if ghelp.IsDir(out) {
		logs.Error("%s is exist", out)
		os.Exit(1)
	}
	output, err := utils.ExecCommand("git", "clone", skeletonGitUrl, out)
	if err != nil {
		logs.Error("git clone err:", err)
		os.Exit(1)
	}
	logs.Info(output)
	if ghelp.IsDir(filepath.Join(out, ".git")) {
		os.RemoveAll(filepath.Join(out, ".git"))
	}
}
